#include "Http.hpp"


void Login(HttpRequest &req, HttpResponse &resp)
{
    LOG(LogLevel::DEBUG) << "测试函数Login被调用";
    std::string text = "test for " + req.Get_args(); // 测试text

    resp.SetCode("200");                                 // 设置状态码
    resp.SetHeader("Content-Type", "text/plain");         // 设置响应报头
    resp.SetHeader("Content-Length", std::to_string(text.size())); // 设置响应报头
    resp.SetText(text);                               // 设置响应正文
}


// 
int main(int argc, char *argv[]) 
{
    // 检查输入格式
    if (argc != 2)
    {
        std::cout << "输入格式错误! Usage: " << argv[0] << " port" << std::endl;
        exit(USAGE_ERR);
    }

    uint16_t port = std::stoi(argv[1]); // 获取输入端口号

    // 创建http对象
    std::unique_ptr<Http> httpsvr = std::make_unique<Http>(port);
    // 添加login服务
    httpsvr->RegisterService("/login", Login);

    httpsvr->Start(); // 启动http服务
    
    return 0;
}

